package com.example.javaee.controller;

import com.example.javaee.domain.User;
import com.example.javaee.exception.UserAdminException;
import com.example.javaee.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController
{
    @Autowired
    UserService userService;
    @PutMapping("/{userId}")
    void updateUserInfo(@PathVariable Integer userId, @RequestBody User user)  throws UserAdminException
    {
        userService.updateUserInfo(userId, user);
        return ;
    }

    @PutMapping("/updatePassword")
    public void updatePassword(String oldPassword, String newPassword) throws UserAdminException {
        userService.updatePassword(oldPassword, newPassword);
    }

    @GetMapping("/getAllUsers")
    public List<User> getAllUsers(){
        return userService.getAllUsers();
    }

    @DeleteMapping("/deleteUser")
    public void deleteUser(Integer id){
        userService.deleteUser(id);
    }


}
